'plot fish  csc 10/25/92

PRINT "read fish data file for model fish calculations"
PRINT "The fish model is constructed of short cylinders"
PRINT "data files are for fish body (flesh) and swimbladder"
PRINT "Although we expect the fish to scale, individual animals
PRINT "can be put in the arrays"
PRINT"---data files contain headers and identifiers"
PRINT"   fish flesh density, gas density and sound speeds are in"
PRINT"   scattering prgms."

DIM xfb(50),zufb(50),zlfb(50),wfb(50), xsb(50),zusb(50),zlsb(50),wsb(50)
DIM u(50),vm(50),vu(50),eas(50),ma(50),du(50),bu(50),maf(50),uf(50)
DIM vmf(50),vuf(50),maf(50),duf(50),buf(50),dxf(50),vlf(50),blf(50)
DIM fd(200),yd(200)

sF = 1: pi = 4*ATN(1): lcnvm = .001 : vcnvm = 1E-09
fbd = 1050 :'kg/m^3
fd = 1050 :sbd = 124
cfb = 1578:csb = 345


 'words for file
words1$ = "caudal fish length mm ="
words2$ = "fish mass g ="
words5$ = "fish body"
words6$ = "swimbladder"
words7$ =  "x, z-upper, z-lower, width"

20 PRINT"menu"
PRINT"  enter 'r' to rotate fish"
PRINT"        'df' to read default file"
PRINT"        'rf' to read old file"
PRINT"        's' to scale fish to new length"
PRINT"        'c' to compute volume and mass"
PRINT"        'g'  to graph  file"
PRINT"        'mf' to make file"
PRINT"        'q'  to quit"

INPUT q$
IF q$ = "r" GOTO 100
IF q$ = "df" GOTO 800
IF q$ = "rf" GOTO 2000
IF q$ = "c" GOTO 600
IF q$ = "s" GOTO 700
IF q$ = "g" GOTO 300
IF q$ = "mf" GOTO 200
IF q$ = "q" GOTO 1000
GOTO 20

100 ' compute equivalent cylinders
'convert initial fish dimensions in mm to m 
' fish body ---   dxf(50),mxf(50),mzf(50),eaf(50)
' swimbladder --- dxs(50),mxs(50),mzs(50),eas(50)

'u and v are rotated axis rotation is theta in std cyl scat convention.
'u is along the incident wave front
'v is along the ray path back to the receiver
'theta = pi/2 is normal incidence on the cylinder.

' u(j) is the rotated displacement of the center of jth
' element of cylinder along the axis of the cylinder
' vm(j) is the v  of the mean of the  jth element of cylinder.
' vu(j) is the displacement of the top (upper face)
'  of jth element of cylinder
' ma(j) is the mean half width of the upper face
' bu(j) is the slope of the upper face
' du(j) is the length
PRINT" fish length = ";fL;" mm"
sbL =xsb(Nsb)-xsb(0)
PRINT" swimbladder length = ";sbL;" mm"
PRINT "  old theta =";theta*180/pi;" new=";: INPUT thetad
theta = thetad*pi/180

'geometry for breathing mode volume dv(j) and scatter from upper face
snth=SIN(theta)
csth = COS(theta)
PRINT "u(j)", "vu(j)", "vl(j)", "dv(j) ml swim bladder"
FOR j = 0 TO Nsb-1
    z0 = (zusb(j)-zlsb(j))/2
    z1 = (zusb(j+1)-zlsb(j+1))/2
    y0 = wsb(j)/2
    y1 = wsb(j+1)/2
    dx = xsb(j+1)-xsb(j)
    dxs(j) = dx
    xm = xsb(j) + dx/2 
    duz = zusb(j+1)-zusb(j)
    zm = (zusb(j)+zlsb(j) + zusb(j+1)+zlsb(j+1) ) /4
    zus = (zusb(j) + zusb(j+1)) /2
    yb = (y1-y0)/dx
    zb = (z1-z0)/dx
    dv(j) = pi*ABS( (z0*y0*dx + (zb*y0+yb*z0)*dx^2/2 + zb*yb*dx^3/3 ) )
    eas(j) = SQR(dv(j)/(pi*dx))
    u(j) = xm*snth - zm*csth
    vm(j) = xm*csth+zm*snth
    vu(j) = xsb(j)*csth + zusb(j)*snth
    vl(j) = xsb(j)*csth + zlsb(j)*snth
    ma(j) =  (y0 + y1)/2
    du(j) = dx*snth
    IF du(j)<>0 THEN bu(j) = (dx*csth+duz*snth)/du(j)
    
   PRINT INT(10*u(j))/10,INT(10*vu(j))/10,INT(10*vl(j))/10,INT(dv(j)/100)/10
NEXT j
INPUT q$
 
'PRINT "j", "u(j)", "vu(j)"
FOR j = 0 TO Nfb-1
    z0 = (zufb(j)-zlfb(j))/2
    z1 = (zufb(j+1)-zlfb(j+1))/2
    y0 = wfb(j)/2
    y1 = wfb(j+1)/2
    dx = xfb(j+1)-xfb(j)
    xm = xfb(j) + dx/2 
    duz = zufb(j+1)-zufb(j)
    zm = (zufb(j)+zlfb(j) + zufb(j+1)+zlfb(j+1) ) /4
    zus = (zufb(j) + zufb(j+1)) /2
    yb = (y1-y0)/dx
    uf(j) = xm*snth - zm*csth
    vmf(j) = xfb(j)*csth+zm*snth
    vuf(j) = xfb(j)*csth + zus*snth
    maf(j) =  (y0 + y1)/2
    duf(j) = dx*snth
    IF duf(j)<>0 THEN buf(j) = (dx*csth+duz*snth)/duf(j)
'   PRINT j,maf(j),vuf(j),buf(j),uf(j)
NEXT j
'INPUT q$

PRINT "j", "u(j)", "vu(j)", "vl(j)"
FOR j = 0 TO Nfb-1
    z0 = (zlfb(j)-zlfb(j))/2
    z1 = (zlfb(j+1)-zlfb(j+1))/2
    y0 = wfb(j)/2
    y1 = wfb(j+1)/2
    dx = xfb(j+1)-xfb(j)
    xm = xfb(j) + dx/2 
    dlz = (zlfb(j+1)-zlfb(j))
    zm = (zufb(j)+zlfb(j) + zufb(j+1)+zlfb(j+1) ) /4
    zls = (zlfb(j) + zlfb(j+1)) /2
    yb = (y1-y0)/dx
    vlf(j) = xm*csth + zls*snth
    IF duf(j)<>0 THEN blf(j) = (dx*csth+dlz*snth)/duf(j)    
   PRINT j,INT(10*uf(j))/10,INT(10*vuf(j))/10,INT(10*vlf(j))/10
NEXT j
INPUT q$
 GOTO 20


200 ' make file. chose tt and kk to give 0.1 mm
tt = 10: kk = 10
PRINT "file in prgm ";name1$
PRINT "file read ";name2$
PRINT "name new file";:INPUT name1$
 OPEN name1$ FOR OUTPUT AS #1
 WRITE #1, ftype$
 WRITE #1, words1$,sL
 WRITE #1, words2$,mfb
 WRITE #1,Nfb
 WRITE #1,words7$
 WRITE #1,words5$
 FOR n = 0 TO Nfb
    WRITE #1,INT(tt*sF*xfb(n))/kk,INT(tt*sF*zufb(n))/kk,INT(tt*sF*zlfb(n))/kk,INT(tt*sF*wfb(n))/kk
 NEXT n
 
 WRITE #1, words6$
  WRITE#1, Nsb
  FOR n = 0 TO Nsb
    WRITE #1,INT(tt*sF*xsb(n))/kk,INT(tt*sF*zusb(n))/kk,INT(tt*sF*zlsb(n))/kk,INT(tt*sF*wsb(n))/kk
 NEXT n
 
 WRITE #1,words8$
 
 CLOSE #1
 GOTO 20
 
300  G0 = 20: G1 = 460: G2 = 20: G3 = 260: '   PLOT WINDOW LIMITS X,Y
 XS = (G1-G0)/fL
 YS = XS
 z0 = G3/2
 zw = 3*G3/4
 
 CLS         : ' CLS clears the screen
 PICTURE ON  : ' PICTURE ON puts screen graphics in storage.
 SHOWPEN     : ' SHOWPEN also puts graphics on the screen 

LINE (G0,G2) - (G1,G2)
LINE (G0,G3) - (G1,G3)
LINE (G0,G2) - (G0,G3)
LINE (G1,G2) - (G1,G3)

' plot upper side fish body
 FOR n = 0 TO Nfb-2
         xp = sF*(uf(n)-du(n)/2) * XS +G0
         xp1 = sF*(uf(n+1)- du(n+1)/2) * XS +G0
          zp = z0-sF*vuf(n) *YS
          zp1 = z0-sF*vuf(n+1) *YS
         LINE (xp,zp) - (xp1,zp1)
 NEXT n
 'plot lower side
  FOR n = 0 TO Nfb-2
         xp = sF*(uf(n)-du(n)/2) * XS +G0
         xp1 = sF*(uf(n+1)-du(n)/2) * XS +G0
          zp = z0-sF*vlf(n) *YS
          zp1 = z0-sF*vlf(n+1) *YS
         LINE (xp,zp) - (xp1,zp1)
 NEXT n

 ' plot upper side swimbladder
 FOR n = 0 TO Nsb-2
         xp = sF*(u(n)-du(n)/2) * XS +G0
         xp1 = sF*(u(n+1)-du(n)/2) * XS + G0
          zp = z0-sF*vu(n) *YS
          zp1 = z0-sF*vu(n+1) *YS
         LINE (xp,zp) - (xp1,zp1)
 NEXT n
           xp = sF*(u(Nsb-1)+du(Nsb-2)/2)* XS +G0
         xp1 = sF*(u(Nsb-1)+du(Nsb-2)/2) * XS +G0
          zp = z0-sF*vu(Nsb-1) *YS
          zp1 = z0-sF*vu(Nsb) *YS
         LINE (xp,zp) - (xp1,zp1)

 'plot lower side
  FOR n = 0 TO Nsb-2
         xp = sF*(u(n)-du(n)/2)* XS +G0
         xp1 = sF*(u(n+1)-du(n)/2) * XS +G0
          zp = z0-sF*vl(n) *YS
          zp1 = z0-sF*vl(n+1) *YS
         LINE (xp,zp) - (xp1,zp1)
 NEXT n
          xp = sF*(u(Nsb-1)+du(Nsb-2)/2)* XS +G0
         xp1 = sF*(u(Nsb-1)+du(Nsb-2)/2) * XS +G0
          zp = z0-sF*vl(Nsb-2) *YS
          zp1 = z0-sF*vl(Nsb) *YS
         LINE (xp,zp) - (xp1,zp1)

 
  'plot mean
  FOR n = 0 TO Nsb-1
         xp = sF*u(n)* XS +G0
         zp = z0-sF*vm(n) *YS
         LINE (xp+2,zp) - (xp-2,zp)
  LINE (xp,zp+2) - (xp,zp-2)
 NEXT n

'plot top view--------------------
' plot  fish body
' FOR n = 0 TO Nfb-1
'         xp = sF*xfb(n) * XS +G0
'         xp1 = sF*xfb(n+1) * XS +G0
'          zp = zw-sF*wfb(n) *YS/2
'          zp1 = zw-sF*wfb(n+1) *YS/2
'         LINE (xp,zp) - (xp1,zp1)
' NEXT n
 'plot other side
'  FOR n = 0 TO Nfb-1
'         xp = sF*xfb(n) * XS +G0
'         xp1 = sF*xfb(n+1) * XS +G0
'          zp = zw+sF*wfb(n) *YS/2
'          zp1 = zw+sF*wfb(n+1) *YS/2
'         LINE (xp,zp) - (xp1,zp1)
' NEXT n

 ' plot top view side swimbladder
' FOR n = 0 TO Nsb-1
'         xp = sF*xsb(n) * XS +G0
'         xp1 = sF*xsb(n+1) * XS + G0
'          zp = zw-sF*wsb(n) *YS/2
          zp1 = zw-sF*wsb(n+1) *YS/2
'         LINE (xp,zp) - (xp1,zp1)
' NEXT n

 'plot other side
'  FOR n = 0 TO Nsb-1
'         xp = sF*xsb(n)* XS +G0
'         xp1 = sF*xsb(n+1) * XS +G0
'          zp = sF*zw+wsb(n) *YS/2
'          zp1 = sF*zw+wsb(n+1) *YS/2
'         LINE (xp,zp) - (xp1,zp1)
' NEXT n

'print file names etc
CALL MOVETO (G0,280)
 PRINT name1$;"-";ftype$;" fish L =";fL
      INPUT q$

  330 'end of graph operation
 pic$ = PICTURE$ 
 PICTURE OFF
    INPUT q$

     ' make pict file
 PRINT "make a PICT file, y or n ?";:INPUT pf$
 IF pf$ = "y"  GOTO 340

   CLS    :REM clear screen and clean pict memory
  PICTURE ON
  PICTURE OFF

   GOTO 20

340 'make pict file

 CALL MOVETO (50, 25)  
 PRINT  "The picture is in pic$ ("; LEN (pic$); ")"
 pictFile$ = FILES$ (0, "Enter name for PICT file:")
 PRINT "PICT file name is:"; pictFile$
 
REM	SAVE FILE IN 'PICT' FORMATE.

 OPEN pictFile$ FOR OUTPUT AS #4
 
REM	FOR-NEXT LOOP MAKES A HEADER FOR PICT FILE FORMATE.
 FOR i = 1 TO 512
   PRINT  #4, CHR$ (0); 
 NEXT i
 
 PRINT  #4, pic$
 
 CLOSE  :REM the picture 'pic$' is stored as a text file.
 
REM	CHANGE THE FILE TYPE FROM TEXT TO PICT

 NAME pictFile$ AS pictFile$, "PICT"
 
REM	USE MacDraw TO READ THE FILE. THEN, IT CAN BE SAVED AS A MacDraw DRAWING.
 
  CLS    :REM clear screen and clean pict memory
 PICTURE ON
 PICTURE OFF: 'clean memory
 
GOTO 20

600 'compute volumes and mass
' xfb(50),zufb(50),zlfb(50),wfb(50), xsb(50),zusb(50),zlsb(50),wsb(50)
' deltaV = pi*(z0^2*dx + b*z0*dx^2 + b^2*dx^3/3)*vcnvm , mm -> m

vsb = 0 :vfb = 0
FOR n = 0 TO Nsb-1
    z0 = sF*(zusb(n)-zlsb(n))/2
    z1 = sF*(zusb(n+1)-zlsb(n+1))/2
    y0 = sF*wsb(n)/2
    y1 = sF*wsb(n+1)/2
    dx = sF*(xsb(n+1)-xsb(n))
    zb = (z1-z0)/dx
    yb = (y1-y0)/dx
    vv = pi*(z0*y0*dx + (zb*y0+yb*z0)*dx^2/2 + zb*yb*dx^3/3 )
   vsb = vsb+vv*vcnvm
NEXT n

FOR n = 0 TO Nfb-1
    z0 = sF*(zufb(n)-zlfb(n))/2
    z1 = sF*(zufb(n+1)-zlfb(n+1))/2
    y0 = sF*wfb(n)/2
    y1 = sF*wfb(n+1)/2
    dx = sF*(xfb(n+1)-xfb(n))
    zb = (z1-z0)/dx
    yb = (y1-y0)/dx
    vv = pi*(z0*y0*dx + (zb*y0+yb*z0)*dx^2/2 + zb*yb*dx^3/3)
   vfb = vfb+vv*vcnvm
NEXT n

massf = (vfb-vsb)*fd
PRINT " fish volume = "; INT(vfb*1000000!); " cm^3"
PRINT " swimbladder = "; INT(vsb*1E+07+.5)/10; " cm^3"
PRINT "   sb length = "; xsb(Nsb)-xsb(0);" mm"
PRINT"        using flesh density =";fd;" kg/m^3"
PRINT " mass fish = "; INT(massf*1000!); " g"
PRINT " meas mass = "; mfb; " g"
GOTO 20

700 ' scale fish
PRINT"xfb(Nfb) =";xfb(Nfb)
PRINT "fish length ="; fL
PRINT "input new scale length";:INPUT sL
sF = sL/xfb(Nfb)
GOTO 20

800 name1$ = "horne cod D"

ftype$ = "cod D, CL 380/TL 412mm/544g"
 fL = 380  :' caudal length
 sL = 380
 mfb = 544
 fd = 1050 :sbd = 124
 cfb = 1578:csb = 345

    Nfb = 10
' enter x, z-upper, z-lower, width

 xfb(0)=0:    zufb(0)=5:  zlfb(0)=-10: wfb(0)=20
 xfb(1)=41:   zufb(1)=20: zlfb(1)=-25: wfb(1)=45
 xfb(2)=83:   zufb(2)=30: zlfb(2)=-30: wfb(2)=57
 xfb(3)=124:  zufb(3)=30: zlfb(3)=-45: wfb(3)=60
 xfb(4)=165:  zufb(4)=27: zlfb(4)=-47: wfb(4)=49
 xfb(5)=206:  zufb(5)=23: zlfb(5)=-40: wfb(5)=35
 xfb(6)=247:  zufb(6)=15: zlfb(6)=-29: wfb(6)=23
 xfb(7)=290:  zufb(7)=10: zlfb(7)=-20: wfb(7)=12
 xfb(8)=330:  zufb(8)=7:  zlfb(8)=-16: wfb(8)=7
 xfb(9)=370:  zufb(9)=5:  zlfb(9)=-13: wfb(9)=3
 xfb(10)=380: zufb(10)=0: zlfb(10)=-5: wfb(10)=1

' swimbladder 
    Nsb = 5
xsb(0)=103: zusb(0)=-2:  zlsb(0)=-10:  wsb(0)=11
xsb(1)=125: zusb(1)=-2:  zlsb(1)=-16: wsb(1)=25
xsb(2)=144: zusb(2)=-3:  zlsb(2)=-20: wsb(2)=23
xsb(3)=165: zusb(3)=-6:  zlsb(3)=-23: wsb(3)=18
xsb(4)=186: zusb(4)=-10: zlsb(4)=-21: wsb(4)=14
xsb(5)=206: zusb(5)=-16: zlsb(5)=-19: wsb(5)=7
 
 words8$ ="from john horne soft x=rays of cod. total length 412 mm/cL 380"
 
PRINT" Horne data on cod"
PRINT" cod    total length    caudal length     mass"
PRINT" A       177 mm                172                   48 g"
PRINT" B        156                  148                   43"
PRINT" C        344                  323                  286"
PRINT" D        412                  380                  544"
PRINT" E         804                 ----                4685"

GOTO 20

 
2000 ' read data file in 'fish data file maker' format
PRINT"read file ";:INPUT name2$
  OPEN name2$ FOR INPUT AS #2
 INPUT #2, ftype$
 INPUT #2, words1$,fL
 INPUT #2, words2$,mfb
 INPUT #2,Nfb
 INPUT #2,words7$
 INPUT #2,words5$
 
 FOR j = 0 TO Nfb
    INPUT #2,xfb(j),zufb(j),zlfb(j),wfb(j)
 NEXT j
 
 INPUT #2, words6$
 
  INPUT #2, Nsb
  FOR j = 0 TO Nsb
    INPUT #2,xsb(j),zusb(j),zlsb(j),wsb(j)
 NEXT j
 
 INPUT #2,words8$
 CLOSE #2
GOTO 20

1000 END
